package cn.wolfcode.luowowo.util;

import lombok.Data;

//定义一个泛型
@Data
public class JsonResult<T> {
    
    private static final int SUCCESS_CODE = 200;
    private static final String SUCCESS_MSG = "验证正确!";
    private static final int REEORVERIFICATION_CODE = 403;
    private static final String ERRORVERIFICATION_MSG = "验证码错误!";
    
    public static final int CODE_NOLOGIN = 401;
    public static final String MSG_NOLOGIN = "请先登录";
    public static final int CODE_ERROR = 500;
    public static final String MSG_ERROR = "系统异常，请联系管理员";
    public static final int CODE_ERROR_PARAM = 501;  //参数异常
   
   
    //定义一个int类型的变量 回馈状态
    private int code;
    //返回的错误信息
    private String msg;
    private T data;  //除了操作结果之后, 还行携带数据返回
    
    //有参数构造器
    public JsonResult(int code, String msg,T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    //成功并且带上返回信息
    public static <T> JsonResult success(T data){
        return new JsonResult(SUCCESS_CODE, SUCCESS_MSG, data);
    }
    //成功的方法
    public  static JsonResult success() {
        return new JsonResult(SUCCESS_CODE, SUCCESS_MSG,null);
    }
    //验证码错误的方法
    public  static JsonResult ErrorSuccess() {
        return new JsonResult(REEORVERIFICATION_CODE, ERRORVERIFICATION_MSG,null);
    }
    public static JsonResult defaultError(){
        return new JsonResult(CODE_ERROR, MSG_ERROR, null);
    }
    public static <T>  JsonResult error(int code, String msg, T data){
        return new JsonResult(code, msg, data);
    }
    public static JsonResult noLogin() {
        return new JsonResult(CODE_NOLOGIN, MSG_NOLOGIN, null);
    }
    
}
